﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TR.AppService.Dto;
using TR.AppService.Dto.SencDto;
using TR.Domain.Entity;
using TR.Domain.Repository.Sys_EncodeRepository;
using AutoMapper;

namespace TR.AppService.AppService.Sys_Encode
{
    public class Sys_EncodeAppService : ISys_EncodeAppService
    {
        private readonly ISys_EncodeRepository SencRepository;
        private readonly IMapper mapper;

        public Sys_EncodeAppService(ISys_EncodeRepository SencRepository,IMapper mapper)
        {
            this.SencRepository = SencRepository;
            this.mapper = mapper;
        }

        //编码规则新增
        public Task<bool> EncodeAddAsync(SencInsertDto sencInsert)
        {
            sys_Encode senAdd = mapper.Map<sys_Encode>(sencInsert);
            return SencRepository.InsertAsync(senAdd);
        }

        //分页条件查询
        public async Task<DtoFenYe<sys_Encode>> EncodeFenYeSelectAsync(int mys, int dqy, string qsj, string hsj, SencFenyeTjDto senDto)
        {
            sys_Encode sen = mapper.Map<sys_Encode>(senDto);
            var listF = await SencRepository.SencFenyeSelectAsync(mys, dqy, qsj, hsj, sen);
            var ztF = await SencRepository.SencZTSelectAsync();
            var res = new DtoFenYe<sys_Encode>()
            {
                mys = mys,
                dqy = dqy,
                list = listF,
                zts = ztF
            };

            return res;
        }

        //根据编码ID查询
        public async Task<sys_Encode> IDSelectAsync(int id)
        {
            return await SencRepository.IDSelectAsync(id);
        }

        //条件 查询 单条信息表
        public async Task<sys_Encode> TjSelectAsync(string tj)
        {
            return await SencRepository.TjSelectAsync(tj);
        }

        //修改规则信息
        public async Task<bool> UpdelectAsync(SencUpdateDto sencUpdate)
        {
            sys_Encode senUpdate = mapper.Map<sys_Encode>(sencUpdate);
            return await SencRepository.UpdelectAsync(senUpdate);
        }
    }
}
